package com.one.shopping.ui.baseActivity;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.one.shopping.R;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/8 15:21
 */
public abstract class BaseActivity extends Activity {

    protected ImageView returnBtn;
    protected ImageView scanBtn;
    protected ImageView queryBtn;
    protected EditText queryField;
    protected TextView titleValue;
    protected ImageView addBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentViewId());

        initView();
        initListener();
        initData();
        initEvent();
    }

    protected void initView() {
        returnBtn = findView(R.id.main_return_btn_iv);
        scanBtn = findView(R.id.main_scan_btn_iv);
        queryBtn = findView(R.id.main_query_btn_iv);
        queryField = findView(R.id.main_query_values_et);
        titleValue = findView(R.id.main_title_tv);
        addBtn = findView(R.id.main_add_btn_iv);
        isVisibleQuery(false);
        isVisibleReturn(false);
        isVisibleScanFind(false);
        isVisibleTitle(true);
        isVisibleAdd(false);
    }




    protected void initEvent() {

    }

    protected void initData() {

    }

    protected void initListener() {

    }

    /**
     * 设置标题
     */
    public void setTitle(String title) {
        if (titleValue != null) {
            titleValue.setText(title);
        }
    }

    /**
     * 是否显示返回按钮
     */
    public void isVisibleReturn(boolean tag) {
        if (returnBtn != null) {
            if (tag)
                returnBtn.setVisibility(View.VISIBLE);
            else
                returnBtn.setVisibility(View.GONE);
        }
    }

    /**
     * 是否显示查询按钮
     */
    public void isVisibleQuery(boolean tag) {
        if (queryBtn != null) {
            if (tag)
                queryBtn.setVisibility(View.VISIBLE);
            else
                queryBtn.setVisibility(View.GONE);
        }
    }

    /**
     * 是否显示标题
     */
    public void isVisibleTitle(boolean tag) {
        if (titleValue != null) {
            if (tag)
                titleValue.setVisibility(View.VISIBLE);
            else
                titleValue.setVisibility(View.GONE);
        }
    }

    /**
     * 是否显示扫描按钮和输入框
     */
    public void isVisibleScanFind(boolean tag) {
        if (scanBtn != null && queryField != null) {
            if (tag) {
                scanBtn.setVisibility(View.VISIBLE);
                queryField.setVisibility(View.VISIBLE);
            } else {
                scanBtn.setVisibility(View.GONE);
                queryField.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 是否显示添加按钮
     */
    public void isVisibleAdd(boolean tag) {
        if (addBtn != null) {
            if (tag) {
                addBtn.setVisibility(View.VISIBLE);
            } else {
                addBtn.setVisibility(View.GONE);
            }
        }

    }



    protected void makeToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    protected abstract int getContentViewId();

    public <T extends View> T findView(int id) {
        return (T) super.findViewById(id);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }


}
